package MyFilter;

import javax.servlet.*;
import javax.servlet.annotation.*;
/*
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebFilter(filterName = "LoginFilter", urlPatterns = "/*", initParams = {

})
public class LoginFilter implements Filter {
    public void init(FilterConfig config) throws ServletException {
    }

    public void destroy() {
    }

    @Override
    public void doFilter(ServletRequest request1, ServletResponse response1, FilterChain chain) throws ServletException, IOException {
        HttpServletRequest request = (HttpServletRequest) request1;
        HttpServletResponse response = (HttpServletResponse) response1;
        String url = request.getRequestURI();
        HttpSession session = request.getSession();
        String userName = (String) session.getAttribute("userName");
        if (userName != null || url.indexOf("login") != -1 ||
                url.indexOf("layui") != -1 ||
                url.indexOf("css") != -1 ||
                url.indexOf("js") != -1 ||
                url.indexOf("favicon.ico") != -1 ||
                url.indexOf("/adminLogin") != -1 ||
                url.indexOf("/teacherLogin") != -1 ||
                url.indexOf("/stuLogin") != -1 ||
                url.indexOf("img") != -1) {
            chain.doFilter(request, response);
        } else {
            response.sendRedirect("http://localhost/login.jsp");
        }

    }
}
*/
